package com.ruoyi.home.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.OrderNumberGeneratorUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.date.DateUtils;
import com.ruoyi.common.utils.parameter.DistanceUtil;
import com.ruoyi.dynamic.domain.UserDynamic;
import com.ruoyi.dynamic.domain.UserDynamicTime;
import com.ruoyi.dynamic.mapper.UserDynamicMapper;
import com.ruoyi.dynamic.mapper.UserDynamicTimeMapper;
import com.ruoyi.framework.security.auth.JWTUser;
import com.ruoyi.framework.security.auth.RequestContext;
import com.ruoyi.home.pojo.AppHomeDTO;
import com.ruoyi.home.pojo.AppHomeVO;
import com.ruoyi.home.pojo.AppMyServiceDTO;
import com.ruoyi.home.pojo.AppRanking;
import com.ruoyi.home.pojo.AppWithdrawalVO;
import com.ruoyi.home.service.AppHomeService;
import com.ruoyi.order.domain.OrderInfo;
import com.ruoyi.order.mapper.OrderInfoMapper;
import com.ruoyi.problem.mapper.ProblemAnswerMapper;
import com.ruoyi.system.domain.PriceSetting;
import com.ruoyi.system.domain.SystemDivine;
import com.ruoyi.system.mapper.PriceSettingMapper;
import com.ruoyi.system.mapper.SystemDivineMapper;
import com.ruoyi.thread.TaskAsync;
import com.ruoyi.user.domain.FileAttachment;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.domain.UserCapitalFlow;
import com.ruoyi.user.domain.UserThirdParty;
import com.ruoyi.user.domain.UserTotalCapital;
import com.ruoyi.user.domain.UserVoiceCall;
import com.ruoyi.user.domain.UserWithdrawRecord;
import com.ruoyi.user.mapper.FileAttachmentMapper;
import com.ruoyi.user.mapper.UserMapper;
import com.ruoyi.user.mapper.UserThirdPartyMapper;
import com.ruoyi.user.mapper.UserVoiceCallMapper;
import com.ruoyi.user.mapper.UserWithdrawRecordMapper;
import com.ruoyi.user.service.IUserCapitalFlowService;
import com.ruoyi.user.service.IUserTotalCapitalService;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;

@Service
public class AppHomeServiceImpl implements AppHomeService {

	@Autowired
	private UserMapper userMapper;
	@Autowired
	private TaskAsync taskAsync;
	@Autowired
	private UserThirdPartyMapper userThirdPartyMapper;
	@Autowired
	private IUserTotalCapitalService userTotalCapitalService;
	@Autowired
	private UserWithdrawRecordMapper userWithdrawRecordMapper;
	@Autowired
	private IUserCapitalFlowService userCapitalFlowService;
	@Autowired
	private UserDynamicMapper userDynamicMapper;
	@Autowired
	private SystemDivineMapper systemDivineMapper;
	@Autowired
	private ProblemAnswerMapper problemAnswerMapper;
	@Autowired
	private UserVoiceCallMapper userVoiceCallMapper;
	@Autowired
	private OrderInfoMapper orderInfoMapper;
	@Autowired
	private UserDynamicTimeMapper userDynamicTimeMapper;
	@Autowired
	private FileAttachmentMapper fileAttachmentMapper;
	@Autowired
	private PriceSettingMapper priceSettingMapper;
	
	
	/**
	 * 	获取用户ID
	 * @return
	 */
	private Long getLoginUserId() {
		Object object = RequestContext.get("userInfo");
		if(null == object) {
			return null;
		}
		JWTUser jwtUser = (JWTUser) object;
		if(null == jwtUser || null == jwtUser.getId()) {
			return null;
		}
		return jwtUser.getId();
	}
	
	@Override
	public AjaxResult homeUserList(String sex,String longitude,String latitude,Integer pageNo, String city,String nickName,HttpServletRequest request) {
		try {
			Long loginUserId = getLoginUserId();
			if(null == loginUserId) {
				return AjaxResult.error(50010,"请重新登录");
			}
			User cuuser = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, loginUserId)
					.select(User::getVip,User::getId,User::getSex,User::getEnabled));
			if(null == cuuser) {
				return AjaxResult.error(50010,"请重新登录");
			}
			if(2 == cuuser.getEnabled()) {
				return AjaxResult.error(50010,"请重新登录");
			}
			if("F".equalsIgnoreCase(cuuser.getSex())) {
				sex = "M";
			}else {
				sex = "F";
			}
			IPage<AppHomeDTO> homeUserChoose = userMapper.homeUserChoose(new Page<AppHomeVO>().setCurrent(pageNo).setSize(10), 0, nickName,sex, "",new BigDecimal(longitude)
					,new BigDecimal(latitude),city,qryWeekType());
			homeUserChoose.getRecords().stream().forEach(user ->{
				//处理年龄
				if(null != user.getBirthday()) {
					user.setAge(CommonUtil.getAge(user.getBirthday()));
				}else {
					user.setAge(22);
				}
				if(user.getDistance().compareTo(new BigDecimal("9999999")) == 0) {
					user.setDistance(new BigDecimal("-1"));
				}
				user.setDistanceShow((DistanceUtil.transferDistance(
						user.getDistance()==null?new BigDecimal("0").doubleValue():user.getDistance().doubleValue())));
				// 处理在线时长
				if(null != user.getLoginTime()) {
					user.setLoginTimeShow(DateUtils.getLoginTimeHome(user.getLoginTime()));
				}
				// 处理虚拟用户距离
				if(3 == user.getEnabled()) {
					if(user.getVirtuallyDistance() > 0) {
						user.setDistanceShow(user.getVirtuallyDistance()+"km");
					}else {
						user.setDistanceShow(DistanceUtil.getVirtuallyDistance());
					}
					if(StringUtils.isNotEmpty(user.getEmUsername())) {
						user.setLoginTimeShow("在线");
					}else {
						user.setLoginTimeShow("最近活跃");
					}
					if(StringUtils.isNotEmpty(user.getVirtuallyStatus())) {
						user.setLoginTimeShow(user.getVirtuallyStatus());
					}
				}
				// 处理距离 2024-08-30 隐藏距离
				user.setDistanceShow("");
				// 相册
				List<FileAttachment> fileList = fileAttachmentMapper.selectList(new LambdaQueryWrapper<FileAttachment>()
						.eq(FileAttachment::getFileModule, "photo").eq(FileAttachment::getUserId, user.getUserId()));
				if(CollectionUtil.isNotEmpty(fileList)) {
					user.setPhotoList(fileList);
					user.setRealPersonAuth(1);
				}
				// 处理约玩类型
				if(StringUtils.isNotEmpty(user.getLable())) {
					String priceName = "";
					if(user.getLable().contains(",")) {
		    			String[] split = user.getLable().split(",");
		    			String type = "";
		    			for (String string : split) {
		    				type += "'"+string+"',";
						}
		    			priceName = type.substring(0,type.length()-1);
		    		}else {
		    			priceName = "'"+priceName+"'";
		    		}
					List<PriceSetting> playList = priceSettingMapper.getPlayList("约玩类型",priceName);
					if(CollectionUtil.isNotEmpty(playList)) {
						user.setPlayList(playList);
					}
				}
				if(!"112".equals(longitude) && !"28".equals(latitude)) {
					taskAsync.update_user_positionn(city, loginUserId, new BigDecimal(longitude), new BigDecimal(latitude), null, null);
				}
			});
			// 更新用户在线时间、VIP状态
			taskAsync.updateUserStatus(loginUserId);
			return AjaxResult.success(homeUserChoose.getRecords());
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("网络繁忙");
		}
	}

	@Override
	public AjaxResult doWithdrawal(AppWithdrawalVO appWithdrawal) {
		try {
			Long loginUserId = getLoginUserId();
			if(null == loginUserId) {
				return AjaxResult.error(50010,"请重新登录");
			}
			// 获取三方账号 userThirdPartyMapper
			UserThirdParty third = userThirdPartyMapper.selectOne(new LambdaQueryWrapper<UserThirdParty>().eq(UserThirdParty::getUserId, loginUserId));
			if (third == null) {
				return AjaxResult.error(500266,"请先绑定账号");
			}
			// 判断日期
//			PriceSetting set = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>().eq(PriceSetting::getPriceType, "提现日期").last("limit 1"));
//			if(null != set && StringUtils.isNotEmpty(set.getPriceName())) {
//				int thisDayOfMonth = DateUtil.thisDayOfMonth();
//				if(!set.getPriceName().equals(String.valueOf(thisDayOfMonth))) {
//					return AjaxResult.error("只能在每月的25号进行提现！");
//				}
//			}
			if(1 == appWithdrawal.getWithdrawTo()) {//微信
				if(StringUtils.isEmpty(third.getOpenId())) {
					return AjaxResult.error(500266,"请先绑定微信");
				}
				return handleWithdrawal(loginUserId,appWithdrawal.getType(), appWithdrawal.getWithdrawAmount(), appWithdrawal.getWithdrawTo(), 
						third.getOpenId(), "");
			}else if(2 == appWithdrawal.getWithdrawTo()) {// 支付宝
				if(StringUtils.isEmpty(third.getAlipayUserName()) || StringUtils.isEmpty(third.getAlipayAccount())) {
					return AjaxResult.error(500266,"请先绑定支付宝");
				}
				return handleWithdrawal(loginUserId,appWithdrawal.getType(), appWithdrawal.getWithdrawAmount(), appWithdrawal.getWithdrawTo(), 
						third.getAlipayAccount(),third.getAlipayUserName());
			}else {
				return AjaxResult.error("提现方式无效");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("网络繁忙");
		}
	}

	/**
	 * 	提现操作
	 * @param type
	 * @param withdrawAmount
	 * @param withdrawTo
	 * @param openId
	 * @param alipayUserName
	 * @param alipayAccount
	 * @return
	 */
	private AjaxResult handleWithdrawal(Long userId,Integer type,BigDecimal withdrawAmount,Integer withdrawTo,String backAccount,String realName) {
		UserTotalCapital userTotalCapital = userTotalCapitalService.getOne(new LambdaQueryWrapper<UserTotalCapital>().eq(UserTotalCapital::getAmountType, type)
				.eq(UserTotalCapital::getUserId, userId));
		if(userTotalCapital == null) {
			return AjaxResult.error("余额不足");
		}
		if("1".equals(userTotalCapital.getIsAccountFrozen())) {
			return AjaxResult.error("账户已被冻结，请联系客户！原因："+userTotalCapital.getAccountFrozenExplain());
		}
		BigDecimal usable = userTotalCapital.getTotalAmount().subtract(userTotalCapital.getFrozenAmount());
		if(usable.compareTo(withdrawAmount) < 0) {
			return AjaxResult.error("余额不足");
		}
//		PriceSetting one = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>().eq(PriceSetting::getPriceType, "提现比例")
//				.select(PriceSetting::getId,PriceSetting::getCurrentPrice));
//		BigDecimal scale = new BigDecimal("1");//提现比例
//		if(null != one ) {
//			scale = one.getCurrentPrice();
//		}
//		BigDecimal multiply = withdrawAmount.multiply(scale);
		String orderNo = OrderNumberGeneratorUtil.get();
				UserWithdrawRecord userWithdrawRecord = new UserWithdrawRecord()
				.setUserId(userId)
				.setOrderNo(orderNo)
				.setCreateTime(new Date())
				.setWithdrawAmount(withdrawAmount)
				.setWithdrawTo(withdrawTo)
				.setStatus(0)
				.setWay(type)
				.setRateAmount(BigDecimal.ZERO)
				.setBackAccount(backAccount)
				.setRealName(realName);
		userWithdrawRecordMapper.insert(userWithdrawRecord);
		// 增加冻结金额
		BigDecimal frozenAmount = userTotalCapital.getFrozenAmount().add(withdrawAmount);										
		userTotalCapital.setFrozenAmount(frozenAmount);
		userTotalCapitalService.updateById(userTotalCapital);
		// 添加提现流水
		taskAsync.addUserCapitalFlow(userId, 2L, 2, withdrawAmount, withdrawTo, 0);
		UserCapitalFlow flow = new UserCapitalFlow();
		flow.setType(3);
		flow.setBusinessType(2);
		flow.setAmount(withdrawAmount);
		flow.setUserId(userId);
		flow.setToUserId(2L);
		flow.setOrderNo(orderNo);
		flow.setIsSettle(0);
		flow.setSource(withdrawTo);
		flow.setRelatedId(userWithdrawRecord.getId());
		flow.setRemark("用户提现");
		userCapitalFlowService.save(flow);
		return AjaxResult.success();
	}

	@Override
	public AjaxResult getMyAuthStatus(HttpServletRequest request) {
		Long loginUserId = getLoginUserId();
		if(null == loginUserId) {
			return AjaxResult.error(50010,"请重新登录");
		}
		Map<String,Object> map = new HashMap<String,Object>();
		User user = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, loginUserId).select(User::getId,User::getWechat,User::getRealPersonAuth
				,User::getVoice));
		if(null == user) {
			return AjaxResult.error(50010,"请重新登录");
		}
		map.put("isWechat", StringUtils.isEmpty(user.getWechat())?0:1);
		map.put("isRealPersonAuth", user.getRealPersonAuth());
		map.put("isVoice", StringUtils.isEmpty(user.getVoice())?0:1);
		return AjaxResult.success(map);
	}

	@Override
	public AjaxResult homeUserSearch(String nickName, Integer pageNo, HttpServletRequest request) {
		Long loginUserId = getLoginUserId();
		if(null == loginUserId) {
			return AjaxResult.error(50010,"请重新登录");
		}
		//pageNo = (pageNo -1)*10;
		AppHomeVO vo = new AppHomeVO();
		vo.setNickName(nickName);
		IPage<AppHomeDTO> list = userMapper.homeUserList(new Page<AppHomeVO>().setCurrent(pageNo).setSize(10), vo);
		list.getRecords().stream().forEach(u ->{
			if(1 == u.getOnlineStatus() ) {
				u.setOnlineStatus(3);
			}else {
				u.setOnlineStatus(DateUtils.getTimeCompareStringold(u.getLoginTime()));
			}
			//处理年龄
			if(null != u.getBirthday()) {
				u.setAge(CommonUtil.getAge(u.getBirthday()));
			}else {
				u.setAge(22);
			}
			// 处理约玩类型
			if(StringUtils.isNotEmpty(u.getLable())) {
				String priceName = "";
				if(u.getLable().contains(",")) {
	    			String[] split = u.getLable().split(",");
	    			String type = "";
	    			for (String string : split) {
	    				type += "'"+string+"',";
					}
	    			priceName = type.substring(0,type.length()-1);
	    		}else {
	    			priceName = "'"+priceName+"'";
	    		}
				List<PriceSetting> playList = priceSettingMapper.getPlayList("约玩类型",priceName);
				if(CollectionUtil.isNotEmpty(playList)) {
					u.setPlayList(playList);
				}
			}
		});
		return AjaxResult.success(list.getRecords());
	}
	
	@Override
	public AjaxResult getQAResults(Integer type, HttpServletRequest request) {
		Long loginUserId = getLoginUserId();
		if(null == loginUserId) {
			return AjaxResult.error(50010,"请重新登录");
		}
		List<SystemDivine> list = new ArrayList<SystemDivine>();
		if(3 == type || type == 4) {	//	星盘问答 / 六爻
			list = systemDivineMapper.selectList(new QueryWrapper<SystemDivine>().eq("type", type).orderByAsc("RAND()").last("limit 1"));
		}else{
			if(1 == type) {
//				SystemDivine divine = systemDivineMapper.selectOne(new QueryWrapper<SystemDivine>().eq("type", type).orderByAsc("RAND()").last("limit 1"));
				String code = "";
				String codeTwo = "";
				SystemDivine divine = systemDivineMapper.getFilterCodeDivine(1, code,codeTwo);
				code = divine.getExtend2().substring(0,divine.getExtend2().length()-1);
				list.add(divine);
				divine = systemDivineMapper.getFilterCodeDivine(1, code,codeTwo);
				codeTwo = divine.getExtend2().substring(0,divine.getExtend2().length()-1);
				list.add(divine);
				divine = systemDivineMapper.getFilterCodeDivine(1, code,codeTwo);
				list.add(divine);
				
			}else {
				for (int i = 1; i <= 3; i++) {
					SystemDivine divine = systemDivineMapper.selectOne(new QueryWrapper<SystemDivine>().eq("type", type).likeRight("extend2", i).orderByAsc("RAND()").last("limit 1"));
					list.add(divine);
				}
			}
		}
		return AjaxResult.success(list);
	}

	@Override
	public AjaxResult getRankingList(Integer pageNo, HttpServletRequest request) {
		IPage<AppRanking> rankingList = userMapper.getRankingList(new Page<AppRanking>().setCurrent(pageNo).setSize(10));
		rankingList.getRecords().stream().forEach(rank ->{
			//处理年龄
			if(rank.getBirthday() != null) {
				rank.setAge(CommonUtil.getAge(rank.getBirthday()));
			}else {
				rank.setAge(22);
			}
		});
		return AjaxResult.success(rankingList);
	}

	@Override
	public AjaxResult myServices(Integer type) {
		Long loginUserId = getLoginUserId();
		if(null == loginUserId) {
			return AjaxResult.error(50010,"请重新登录");
		}
		/**
		 * 	已完成： 
			被采纳的问答
			连麦成功结束
			结束的活动
			咨询项目结束
			未完成：
			发布的活动未开始
			用户下单了咨询项目未开始
		 */
		if(1 == type) {
			// 采纳的问答
			List<AppMyServiceDTO> list = problemAnswerMapper.acceptedAnswersList(loginUserId);
			if(CollectionUtil.isEmpty(list)) list = new ArrayList<AppMyServiceDTO>();
			// 连麦成功结束
			List<UserVoiceCall> voiceList = userVoiceCallMapper.selectList(new LambdaQueryWrapper<UserVoiceCall>().eq(UserVoiceCall::getToUserId, loginUserId).eq(UserVoiceCall::getIsSettle,1)
					.select(UserVoiceCall::getId,UserVoiceCall::getAmount,UserVoiceCall::getCreateTime).orderByDesc(UserVoiceCall::getCreateTime));
			if(CollectionUtil.isNotEmpty(voiceList)) {
				for (UserVoiceCall voice : voiceList) {
					AppMyServiceDTO _my = new AppMyServiceDTO();
					_my.setId(voice.getId());
					_my.setAmount(voice.getAmount());
					_my.setCreateTime(voice.getCreateTime());
					_my.setType(2);
					list.add(_my);
				}
			}
			// 结束的活动
			List<AppMyServiceDTO> myActivity = userDynamicMapper.myActivity(loginUserId, 2);
			if(CollectionUtil.isNotEmpty(myActivity)) list.addAll(myActivity);
			// 咨询项目结束
			List<OrderInfo> orderList = orderInfoMapper.selectList(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getToUserId, loginUserId).eq(OrderInfo::getOrderStatus, 5)
					.eq(OrderInfo::getOrderType, 4).select(OrderInfo::getId,OrderInfo::getOrderAmount,OrderInfo::getCreateTime,OrderInfo::getRelatedId)
					.orderByDesc(OrderInfo::getCreateTime));
			if(CollectionUtil.isNotEmpty(orderList)) {
				for (OrderInfo order : orderList) {
					AppMyServiceDTO _my = new AppMyServiceDTO();
					_my.setId(order.getRelatedId());
					_my.setAmount(order.getOrderAmount());
					_my.setCreateTime(order.getCreateTime());
					_my.setType(4);
					list.add(_my);
				}
			}
			return AjaxResult.success(list);
		}else { // 未完成
			// 未开始的活动
			List<AppMyServiceDTO> list = userDynamicMapper.myActivity(loginUserId, 1);
			if(CollectionUtil.isEmpty(list)) list = new ArrayList<AppMyServiceDTO>();
			// 咨询项目 已下单 但是未开始服务
			List<OrderInfo> orderList = orderInfoMapper.selectList(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getToUserId, loginUserId).eq(OrderInfo::getOrderStatus, 1)
					.eq(OrderInfo::getOrderType, 4).select(OrderInfo::getId,OrderInfo::getOrderAmount,OrderInfo::getCreateTime,OrderInfo::getRelatedId)
					.orderByDesc(OrderInfo::getCreateTime));
			if(CollectionUtil.isNotEmpty(orderList)) {
				for (OrderInfo order : orderList) {
					AppMyServiceDTO _my = new AppMyServiceDTO();
					_my.setId(order.getRelatedId());
					_my.setAmount(order.getOrderAmount());
					_my.setCreateTime(order.getCreateTime());
					_my.setType(4);
					list.add(_my);
				}
			}
			return AjaxResult.success(list);
		}
	}

	@Override
	public AjaxResult myServicesDetail(Long id, Integer type) {
		Long loginUserId = getLoginUserId();
		if(null == loginUserId) {
			return AjaxResult.error(50010,"请重新登录");
		}
		if(2 == type) { // 连麦
			UserVoiceCall voiceCall = userVoiceCallMapper.selectById(id);
			if(null != voiceCall) {
				User user = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, voiceCall.getUserId()).select(User::getId,User::getNickName));
				if(null != user && StringUtils.isNotEmpty(user.getNickName())) {
					voiceCall.setNickName(user.getNickName());
				}
			}
			return AjaxResult.success(voiceCall);
		}else {	// 活动
			UserDynamic dynamic = userDynamicMapper.selectById(id);
			if(null != dynamic) {
				List<UserDynamicTime> list = userDynamicTimeMapper.myActivityDetail(id);
				if(CollectionUtil.isNotEmpty(list)) dynamic.setDynamicTime(list);
			}
			return AjaxResult.success(dynamic);
		}
	}

	// 获取当天星期几
	private Integer qryWeekType() {
		Integer weekType = 1;
		weekType = com.ruoyi.common.utils.date.DateUtil.getWeekOfDateChineseInteger();
		return weekType;
	}
	
	@Override
	public AjaxResult homeUserChoose(String nickName, String lable, String longitude,String latitude, Integer pageNo) {
		Long loginUserId = getLoginUserId();
		if(null == loginUserId) {
			return AjaxResult.error(50010,"请重新登录");
		}
		User cuuser = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, loginUserId).select(User::getId,User::getLoginPointX,User::getLoginPointY
				,User::getSex,User::getEnabled));
		if(null == cuuser) {
			return AjaxResult.error(50010,"请重新登录");
		}
		if(2 == cuuser.getEnabled()) {
			return AjaxResult.error(50010,"请重新登录");
		}
		String sex = "F";
		if("F".equalsIgnoreCase(cuuser.getSex())) {
			sex = "M";
		}else {
			sex = "F";
		}
		System.out.println("经度："+longitude);
		System.out.println("纬度："+latitude);
		IPage<AppHomeDTO> homeUserChoose = userMapper.homeUserChoose(new Page<AppHomeVO>().setCurrent(pageNo).setSize(10), 1, nickName,sex, lable,new BigDecimal(longitude)
				,new BigDecimal(latitude),"",qryWeekType());
		homeUserChoose.getRecords().stream().forEach(user ->{
			//处理年龄
			if(null != user.getBirthday()) {
				user.setAge(CommonUtil.getAge(user.getBirthday()));
			}else {
				user.setAge(22);
			}
			if(user.getDistance().compareTo(new BigDecimal("9999999")) == 0) {
				user.setDistance(new BigDecimal("-1"));
			}
			// 处理距离
			user.setDistanceShow((DistanceUtil.transferDistance(
					user.getDistance()==null?new BigDecimal("0").doubleValue():user.getDistance().doubleValue())));
			// 相册
			List<FileAttachment> fileList = fileAttachmentMapper.selectList(new LambdaQueryWrapper<FileAttachment>()
					.eq(FileAttachment::getFileModule, "photo").eq(FileAttachment::getUserId, loginUserId));
			if(CollectionUtil.isNotEmpty(fileList)) {
				user.setPhotoList(fileList);
				user.setRealPersonAuth(1);
			}
			// 处理在线时长
			if(null != user.getLoginTime()) {
				user.setLoginTimeShow(DateUtils.getLoginTimeHome(user.getLoginTime()));
			}
			if(!"112".equals(longitude) && !"28".equals(latitude)) {
				taskAsync.update_user_positionn("", loginUserId, new BigDecimal(longitude), new BigDecimal(latitude), null, null);
			}
		});
		return AjaxResult.success(homeUserChoose.getRecords());
	}
}
